package com.liehu.business.service;


import com.liehu.business.dao.TypeMapper;
import com.liehu.business.pojo.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;

import java.util.List;

@Service
@Transactional //事务
public class TypeService {
    @Autowired
    private TypeMapper typeMapper;

    @Autowired
    private IdWorker idWorker;

    /**
     * 查询所有
     */
    public List<Type> findAll(){
        return typeMapper.selectList(null);
    }
    /**
     * 根据id查询
     */
    public Type findById(String id){
        return typeMapper.selectById(id);
    }
    /**
     * 插入
     */
    public void save(Type type){
        //给这条记录插入id
        type.setId(idWorker.nextId()+"");
        typeMapper.insert(type);
    }
    /**
     * 更新
     */
    public void update(Type type){
        typeMapper.updateById(type);
    }
    /**
     * 根据id删除
     */
    public void deleteById(String id){
        typeMapper.deleteById(id);
    }
}
